From 40745e5cf07639816b07ee167edab712b5b1ef61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ignacy=20Kuchci=C5=84ski?= Date: Fri, 12 Dec 2025 02:32:45 +0100 Subject: [PATCH] authPrompt: Implement screen time ignore button MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Implement screen time ignore button which allows the parent to extend the child’s computer time for the rest of the day. Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/work_items/8578 Part-of: --- .../gnome-shell-sass/widgets/_login-lock.scss | 10 +++ js/gdm/authPrompt.js | 63 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/data/theme/gnome-shell-sass/widgets/_login-lock.scss b/data/theme/gnome-shell-sass/widgets/_login-lock.scss index d11d7224b..5929ccc57 100644 --- a/data/theme/gnome-shell-sass/widgets/_login-lock.scss +++ b/data/theme/gnome-shell-sass/widgets/_login-lock.scss @@ -271,6 +271,16 @@ $_gdm_dialog_width: 25em; .parental-controls-shield-description { text-align: center; } + + .parental-controls-shield-button { + margin-top: 0.85em; + @extend %lockscreen_button; + @extend %title_4; + padding: $base_margin * 4 $base_margin * 11; + color: $_gdm_fg; + background-color: transparentize($_gdm_fg, .9); + border-radius: $forced_circular_radius; + } } // Notifications diff --git a/js/gdm/authPrompt.js b/js/gdm/authPrompt.js index 4a9e4f67b..1486a97fc 100644 --- a/js/gdm/authPrompt.js +++ b/js/gdm/authPrompt.js @@ -1,4 +1,5 @@ import Clutter from 'gi://Clutter'; +import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; import Atk from 'gi://Atk'; import GObject from 'gi://GObject'; @@ -15,6 +16,11 @@ import * as ShellEntry from '../ui/shellEntry.js'; import * as UserWidget from '../ui/userWidget.js'; import {wiggle} from '../misc/animationUtils.js'; +import {loadInterfaceXML} from '../misc/fileUtils.js'; + +const TimerChildIface = loadInterfaceXML('org.freedesktop.MalcontentTimer1.Child'); +const TimerChildProxy = Gio.DBusProxy.makeProxyWrapper(TimerChildIface); + const DEFAULT_BUTTON_WELL_ICON_SIZE = 16; const DEFAULT_BUTTON_WELL_ANIMATION_DELAY = 1000; @@ -29,6 +35,24 @@ class ParentalControlsShield extends St.BoxLayout { x_align: Clutter.ActorAlign.CENTER, }); + this._requestExtensionCookie = null; + + this._timerChildProxy = TimerChildProxy(Gio.DBus.system, + 'org.freedesktop.MalcontentTimer1', + '/org/freedesktop/MalcontentTimer1', + (proxy, error) => { + if (error) + console.error(`Failed to get TimerChild proxy: ${error}`); + }, + null, /* cancellable */ + Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION + ); + + this._timerChildProxy.connectSignal('ExtensionResponse', (proxy, sender, params) => + this._onExtensionResponse(proxy, sender, params)); + + this.connect('destroy', this._onDestroy.bind(this)); + this._titleLabel = new St.Label({ style_class: 'parental-controls-shield-title', text: _('Screen Time Limit Reached'), @@ -41,6 +65,45 @@ class ParentalControlsShield extends St.BoxLayout { }); this._descriptionLabel.clutter_text.line_wrap = true; this.add_child(this._descriptionLabel); + + this._ignoreButton = new St.Button({ + style_class: 'parental-controls-shield-button', + // Translators: this is for ignoring a screen time limit for parental controls + label: _('Ignore'), + x_align: Clutter.ActorAlign.CENTER, + }); + this._ignoreButton.connect('clicked', + () => this._onIgnoreButtonClicked().catch(logError)); + this.add_child(this._ignoreButton); + } + + _onDestroy() { + this._requestExtensionCookie = null; + } + + async _onIgnoreButtonClicked() { + if (this._requestExtensionCookie) + return; + + try { + [this._requestExtensionCookie] = await this._timerChildProxy.RequestExtensionAsync( + 'login-session', + '', + 0, + {}, + Gio.DBusCallFlags.ALLOW_INTERACTIVE_AUTHORIZATION + ); + } catch (e) { + console.warn(`Failed to obtain screen time extension: ${e.message}`); + } + } + + _onExtensionResponse(proxy, sender, [_, cookie]) { + if (this._requestExtensionCookie === null || + cookie !== this._requestExtensionCookie) + return; + + this._requestExtensionCookie = null; } }); -- 2.39.5